using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Hoshimi._Map_.IDManager
{
    public class IDManager
    {
        // VARIABLES
        protected int m_MinID             = 0;
        protected int m_MaxID             = 0;
        protected int m_NextID            = 0;
        protected Queue<int> m_FreeID     = new Queue<int>();

        //GETTERS & SETTERS
        public Queue<int> myFreeID
        {
            get { return m_FreeID; }
            set { m_FreeID = value; }
        }
        public int myNextID
        {
            get { return m_NextID; }
            set { m_NextID = value; }
        }
        public int myMinID
        {
            get { return m_MinID; }
            set { m_MinID = value; }
        }
        public int myMaxID
        {
            get { return m_MaxID; }
            set { m_MaxID = value; }
        }

        // METHODES
        public virtual int getID()
        {
            if (myFreeID.Count > 0)
            {
                return myFreeID.Dequeue();
            }

            myNextID++;

            #if DEBUG
            Debug.Assert(myNextID <= myMaxID, "The next ID reach the MaxID");
            #endif

            return myNextID;
        }

        public virtual void FreeID(int id)
        {
            myFreeID.Enqueue(id);
        }

        // Ctor
        public IDManager(int IDmin, int IDmax)
        {
            #if DEBUG
            Debug.Assert(IDmin < IDmax, "Order problem between min and max ID");
            #endif

            myMinID     = IDmin;
            myMaxID     = IDmax;
            myNextID    = myMinID;
        }
    }
}
